<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-form-item label="开始日期" prop="startTime">
        <el-date-picker
          :style="{ width: '182.5px' }"
          v-model="queryParams.startTime"
          type="date"
          placeholder="选择日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束日期" prop="endTime">
        <el-date-picker
          :style="{ width: '182.5px' }"
          v-model="queryParams.endTime"
          type="date"
          placeholder="选择日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="设备状态" prop="status">
        <el-select
          :style="{ width: '100%' }"
          v-model="queryParams.status"
          placeholder="请选择设备设备状态"
          clearable
          filterable
        >
          <el-option
            v-for="dict in dict.type.device_usage_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:bind:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:bind:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:bind:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table
      v-loading="loading"
      :data="logList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="序号" align="center" prop="id" width="60">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="科室" align="center" prop="belongName" />
      <el-table-column label="设备编号" align="center" prop="hospitalNumber" />
      <el-table-column label="设备状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.device_usage_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column label="时间" align="center" prop="createTime" />
      <el-table-column label="操作人" align="center" prop="createBy" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listLog } from "@/api/system/log";

export default {
  name: "Bind",
  dicts: ["device_status", 'device_usage_status'],
  props: {
    deviceId: Number,
  },
  data() {
    return {
      pointIds: [],
      pointList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备类型&监控项绑定表格数据
      logList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceId: null,
        status: "",
        startTime: "",
        endTime: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // modalityId: [
        //   { required: true, message: "设备类型id不能为空", trigger: "blur" },
        // ],
        // pointId: [
        //   { required: true, message: "监控项id不能为空", trigger: "blur" },
        // ],
        // pointIds: [],
      },
    };
  },
  created() {
    // this.getList();
    // this.getPointList();
  },
  methods: {
    /** 查询设备类型&监控项绑定列表 */
    getList() {
      this.loading = true;
      this.queryParams.deviceId = this.deviceId;
      listLog(this.queryParams).then((response) => {
        this.logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bindId: null,
        modalityId: null,
        pointId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        pointIds: [],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
  watch: {
    deviceId: {
      handler(nval, oval) {
        this.getList();
      },
      immediate: true,
    },
  },
};
</script>
